package net.cloudcodex.client.character.view.panel;

import net.cloudcodex.client.campaign.view.CampaignsView.Message;
import net.cloudcodex.client.widgets.CharacterAvatar;

import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

public class CharacterInfosPanel extends FlowPanel {

	private Message message;

	private String icon;
	private String name;

	private FlowPanel rightPanel = new FlowPanel();
	private FlowPanel leftPanel = new FlowPanel();
	private FlowPanel descriptionPanel = new FlowPanel();
	private Label nameLbl = new Label();
	private Label iconLbl = new Label();
	private TextBox nameTbx = new TextBox();
	private TextBox iconTbx = new TextBox();
	private TextArea descriptionTextArea = new TextArea();
	
	private CharacterAvatar avatar = new CharacterAvatar();

	private Label descriptionTitle;

	public CharacterInfosPanel() {
		// leftPanel.setWidth("50%");
		// rightPanel.setWidth("50%");
		HorizontalPanel namePnl = new HorizontalPanel();
		HorizontalPanel iconPnl = new HorizontalPanel();
		namePnl.add(nameLbl);
		namePnl.add(nameTbx);
		
		nameTbx.setHeight("20px");

		leftPanel.add(namePnl);

		iconPnl.add(iconLbl);
		iconPnl.add(iconTbx);
		iconPnl.add(avatar);

		rightPanel.add(iconPnl);
		descriptionTitle = new Label();
		
		descriptionTitle.addStyleName("titlePanel");
		descriptionTextArea.setTitle("description");
		descriptionTextArea.setCharacterWidth(60);
		descriptionTextArea.setVisibleLines(5);
		descriptionPanel.add(descriptionTitle);
		descriptionPanel.add(descriptionTextArea);


		this.add(leftPanel);
		this.add(rightPanel);
		this.add(descriptionPanel);
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public void initComponent() {
		descriptionTitle.setText(message.getPublicDescription());
		nameLbl.setText(message.getNameLbl());
		iconLbl.setText(message.getIconLbl());
		nameTbx.setText(name);
		iconTbx.setTitle("icon");
		nameTbx.setTitle("name");
		iconTbx.setText(icon);
		avatar.initComponent(icon, name, false);
		avatar.resize("30", "30");
	}

	public void refreshIcon(String icon) {
		avatar.initComponent(icon, name, false);
	}

	public HasKeyDownHandlers getNameTextBoxKeyDown() {
		return nameTbx;
	}

	public HasKeyDownHandlers getIconTextBoxKeyDown() {
		return iconTbx;
	}

	public HasKeyUpHandlers getNameTextBoxKeyUp() {
		return nameTbx;
	}

	public HasKeyUpHandlers getIconTextBoxKeyUp() {
		return iconTbx;
	}

	public String getCharacterName() {
		return nameTbx.getText();
	}

	public String getCharacterIcon() {
		return iconTbx.getText();
	}

	public void clearView() {
		nameTbx.setText("");
		iconTbx.setText("");
		descriptionTextArea.setText("");
	}

	public String getDescription() {
		return descriptionTextArea.getText();
	}

}
